package com.example.customview.view

import android.animation.TypeEvaluator
import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.util.AttributeSet
import android.view.View
private val provinces = listOf("北京市",
        "天津市",
        "上海市",
        "重庆市",
        "河北省",
        "山西省",
        "辽宁省",
        "吉林省",
        "黑龙江省",
        "江苏省",
        "浙江省",
        "安徽省",
        "福建省",
        "江西省",
        "山东省",
        "河南省",
        "湖北省",
        "湖南省",
        "广东省",
        "海南省",
        "四川省",
        "贵州省",
        "云南省",
        "陕西省",
        "甘肃省",
        "青海省",
        "台湾省",
        "内蒙古自治区",
        "广西壮族自治区",
        "西藏自治区",
        "宁夏回族自治区",
        "新疆维吾尔自治区",
        "香港特别行政区",
        "澳门特别行政区")
/**
 * Copyright (C), 2018.11-2021.05, 恒丰汇金有限公司<BR/>
 * FileName: CircleView<BR/>
 * Author: JiangYong<BR/>
 * Date: 2021/5/15 15:48<BR/>
 * Description: TODO java类作用描述<BR/>
 * History:<BR/>
 * <time> <version> <desc><BR/>
 *修改时间 版本号 描述
 */
class ProvinceView(context: Context, attrs: AttributeSet?) : View(context, attrs) {

    private val paint = Paint().apply {
        color = Color.BLACK
        isAntiAlias = true
        textSize = 80.dp
        textAlign = Paint.Align.CENTER
    }

    var province = provinces[0]
        set(value) {
            field = value
            invalidate()
        }

    override fun onDraw(canvas: Canvas) {
        canvas.drawText(province, width / 2f, height / 2f, paint);
    }


    class ProvinceEvaluator : TypeEvaluator<Any> {
        override fun evaluate(p0: Float, p1: Any, p2: Any): Any {
            val currentIndex = provinces.indexOf(p1) + (p0 * (provinces.indexOf(p2) - provinces.indexOf(p1))).toInt()
            return provinces[currentIndex]
        }

    }
}